package com.example.waibao.service.impl;


import com.example.waibao.dao.NoticeMapper;
import com.example.waibao.entity.faq;
import com.example.waibao.entity.notice;
import com.example.waibao.mapper.NoticeMapper2;
import com.example.waibao.service.NoticeService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.apache.ibatis.annotations.Mapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.time.LocalDate;
import java.util.Date;
import java.util.List;

@Service
public class NoticeServiceImpl implements NoticeService {

    @Autowired
    private NoticeMapper noticeMapper;

    @Autowired
    private NoticeMapper2 noticeMapper2;
    @Override
    public void setNotice(String message, int sys_id, Date time, int school_id, int type) {
//        java.util.Date day=new Date();
//        SimpleDateFormat sdf= new SimpleDateFormat("yyyy-MM-dd");

       // System.out.println(sdf.format(day));
        noticeMapper.setNotice2( message, sys_id, time, school_id, type);
    }

    @Override
    public List<notice> getNotice() {
        return noticeMapper.getNotice();
    }

    @Override
    public PageInfo<notice> getNotice2(Integer pageNum, Integer pageSize, LocalDate time1, LocalDate time2,int school_id) {

        PageHelper.startPage(pageNum,pageSize);
        List<notice> all = noticeMapper2.getNotice2(time1,time2, school_id);
        PageInfo<notice> dataPageInfo = new PageInfo<>(all);
        return dataPageInfo;
    }

    @Override
    public PageInfo<faq> get_question(Integer pageNum, Integer pageSize,int schoolId, int status) {
        PageHelper.startPage(pageNum,pageSize);
        List<faq> f = noticeMapper2.get_question(schoolId,status);
        PageInfo<faq> dataPageInfo = new PageInfo<>(f);
        return dataPageInfo;
    }

    @Override
    public void solve_question(int questionId, String answer, int sysId) {
        noticeMapper.solve_question(questionId,answer,sysId);
    }

    @Override
    public void delete_question(int questionId) {
        noticeMapper.delete_question(questionId);
    }

    @Override
    public void delete_notice(int id) {
        noticeMapper.delete_notice(id);
    }

    @Override
    public void update_notice(int id, Date date1, String message, Long id1, int type) {
        noticeMapper.update_notice(id,date1,message,id1,type);
    }
}
